package program_structure;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2022/8/22 18:01
 * for循环 明确知道循环次数、迭代条件
 *      for(初始化条件:终止条件（布尔表达式）:循环迭代条件){
 *          循环体...
 *      }
 */
public class ForDemo {
    public static void main(String[] args) {
        //1.for循环计算1-100的和
        int sum = 0;
        for (int i = 0; i < 101; i++) {
            sum+=i;
        }
        System.out.println(sum);
        //2.计算5的阶乘值
        int factor =1;
        for (int i = 1; i < 6; i++) {
            factor*=i;
        }
        System.out.println("5的阶乘："+factor);
        //3.计算1！+2！+3！+4！+5！
        sum=0;
        for (int i = 1; i < 6; i++) {
            factor = 1;
            for (int j = 1; j <= i; j++) {
                factor*=j;
            }
            sum+=factor;
        }
        System.out.println("1！+2！+3！+4！+5！ =  "+sum);
    }
}
